package pers.cz.postgirl.util;

import com.alibaba.fastjson.JSON;
import pers.cz.postgirl.core.Spy;

/**
 * @program: postgirl-client
 * @description: json工具
 * @author: Cheng Zhi
 * @create: 2023-07-31 14:13
 **/
public class JsonUtils {

    /**
     * 将spy对象转换为业务需要的对象
     * @param spy
     * @return
     */
    public static Object spyToObj(Spy spy) {

        String realTypeName = spy.getRealTypeName();
        switch (realTypeName) {
            case "java.lang.ArrayList":
                return JSON.parseArray(JSON.toJSONString(spy.getReturnValue()), ObjUtils.getClass(spy.getGenericsTypeName()));
            default:
                return JSON.parseObject(JSON.toJSONString(spy.getReturnValue()), ObjUtils.getClass(spy.getRealTypeName()));
        }
    }
}
